#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

void Print(int val) {
    cout << val << " ";
}
int main() {
    vector<int> arr;
    arr.push_back(10);
    arr.push_back(20);
    arr.push_back(30);
    arr.push_back(40);

    //遍历方法 1：
    vector<int>::iterator it;
    for (it = arr.begin() ; it != arr.end() ; it++) {
        cout << *it << " ";
    }
    cout << endl;
    //遍历方法 2：
    for_each(arr.begin() , arr.end() ,[](int val){cout << val << " ";});
    cout << endl;
    arr.pop_back();
    for_each(arr.begin() , arr.end() , Print);
    return 0;
}